package com.kaisu.blog.domain.blog;

import com.kaisu.blog.common.util.IdUtils;
import com.kaisu.blog.domain.user.User;
import lombok.Data;

import java.util.Objects;

@Data
public class Like {
    /**
     * id
     */
    private String id;
    /**
     * blog
     */
    private Blog blog;
    /**
     * like user
     */
    private User user;

    public static Like create(User user, Blog blog) {
        Like like = new Like();
        like.setId(IdUtils.generateId());
        like.setUser(user);
        like.setBlog(blog);
        return like;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Like like = (Like) o;
        return Objects.equals(blog.getId(), like.blog.getId()) && Objects.equals(user.getId(), like.user.getId());
    }

    @Override
    public int hashCode() {
        return Objects.hash(blog.getId(), user.getId());
    }
}